/*
 ------------------------------------------------------------------------------
 Copyright (C) 2006-2007 Team Blur.

 This file is part of the Quantum Engine source code.

 The Quantum Engine source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The Quantum Engine source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the Quantum Engine source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


#ifndef __ANIM_H__
#define __ANIM_H__


#define MAX_ANIMATIONS					4096

#define MD5_VERSION_STRING			"MD5Version"
#define MD5_VERSION					10

#define MD5_MAX_JOINTS				128			// Per model
#define MD5_MAX_MESHES				32			// Per model
#define MD5_MAX_VERTICES			4096		// Per mesh
#define MD5_MAX_TRIANGLES			8192		// Per mesh
#define MD5_MAX_WEIGHTS				16384		// Per mesh
#define MD5_MAX_FRAMES				1024		// Per animation

typedef struct {
	char				name[64];
	int					parent;

	int					componentsBits;
	int					componentsOffset;

	odVec3				baseOrigin;
	odQuat				baseQuat;
} animJoint_t;

typedef struct {
	odBounds			bounds;

	float *				components;
} animFrame_t;

typedef struct anim_s {
	char				name[64];

	int					frameRate;
	int					numAnimatedComponents;

	int					numJoints;
	animJoint_t *		joints;

	int					numFrames;
	animFrame_t *		frames;

	struct anim_s *		nextHash;
} anim_t;

enum
{
	COMPONENT_BIT_TX	= 1 << 0,
	COMPONENT_BIT_TY	= 1 << 1,
	COMPONENT_BIT_TZ	= 1 << 2,
	COMPONENT_BIT_QX	= 1 << 3,
	COMPONENT_BIT_QY	= 1 << 4,
	COMPONENT_BIT_QZ	= 1 << 5
};

typedef struct skeleton_s{
	odJointMat	joints[MD5_MAX_JOINTS];
	int	parents[MD5_MAX_JOINTS];
	int numJoints;
	odBounds	bounds;
}skeleton_t;

void Anim_Init (bool isClient);

bool Anim_LoadAnim (const char *name, anim_t *anim);
void Anim_AnimBuildSkeleton(anim_t *anim,skeleton_t *out,float time,bool loop);
void Anim_AnimBlendSkeletons(const skeleton_t *skel1,const skeleton_t *skel2,
						   skeleton_t *res,float frac);
//transforms all bones relative to parent
void Anim_AnimTransformSkeleton(skeleton_t *skel);
anim_t *Anim_RegisterAnimation(const char *name);
int Anim_AnimJointIndex(const anim_t *a,const char *name);


#endif	// __ANIM_H__
